package com.sf.util;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 *提供了onCreate() onUpGrade()等创建数据库与更新数据库的方法
 * 提供了获取数据库对象的函数
 */
public class Mysqlitehelper extends SQLiteOpenHelper {
    private String arr_num [] = new String[100];
    private String arr_name[] = new String[100];
    /**
     * 构造函数
     * @param context  上下文对象
     * @param name  创建的数据库名称
     * @param factory  游标工厂
     * @param version  数据库版本号 >=1
     */
    public Mysqlitehelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public Mysqlitehelper(Context context){
        super(context,Constant.DATABASE_NAME,null,Constant.DATABASE_VERSION);
    }

    /**
     * 当数据库创建时回调的函数
     * @param db 数据库对象
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.i("tag","创建成功");
        //创建数字表
        String num = "create table " + Constant.TABLE_NUM
                + "(" + Constant.ID +" Integer primary key autoincrement,"
                + Constant.NUM + " varchar(10),"
                + Constant.NAME + " varchar(25), "
                + Constant.IMG_URL + " varchar(125) "
                + ")";
        //创建路径
        String path = "create table " + Constant.TABLE_PATH
                + "(" + Constant.ID +" Integer primary key autoincrement,"
                + Constant.NAME + " varchar(25) "
                + ")";

        //创建记忆桩表
        String pile = "create table " + Constant.TABLE_PILE
                + "("
                + Constant.ID + " Integer primary key autoincrement,"
                + Constant.PID +" int(25) ,"
                + Constant.NAME + " varchar(25) ,"
                + Constant.SORT + " int(25) "
                + ")";



        db.execSQL(num); //执行创建数字表
        db.execSQL(path); //执行创建路径表
        db.execSQL(pile); //执行创建记忆桩表


    }

    /**
     *
     * @param db
     * @param oldVersion
     * @param newVersion
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }




}
